import Base from 'models/base';

import moment from 'moment';

export default class MerchantData extends Base {
  constructor(merchant){
    super();

    let majorBranch = merchant.majorBranch;
    this.majorBranch = majorBranch;
    if (majorBranch === 0) {
      let lat = merchant.partnerLatitude;
      if (lat !== null) {
        lat = Number(lat);
      }
      this.lat = lat;
      let lng = merchant.partnerLongitude;
      if (lng !== null) {
        lng = Number(lng);
      }
      this.lng = lng;

      this.name = `${merchant.branchName}-${merchant.partnerName}`;
      this.status = merchant.partnerStatus;
      this.createTime = moment(merchant.partnerCreateTime).valueOf();
    } else {
      let lat = merchant.branchLatitude;
      if (lat !== null) {
        lat = Number(lat);
      }
      this.lat = lat;
      let lng = merchant.branchLongitude;
      if (lng !== null) {
        lng = Number(lng);
      }
      this.lng = lng;

      this.name = merchant.branchName;
      this.status = merchant.branchStatus;
      this.createTime = moment(merchant.branchCreateTime).valueOf();
    }
  }
}